package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.Cls;
import com.qianfeng.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ResponseBody
@Controller
@CrossOrigin
@RequestMapping(value = "/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    @RequestMapping(value = "/addClass")
    public Result addClass(@RequestBody Cls cls){
        classService.addClass(cls);
        Result result = new Result();
        return result;
    }

    /**
     * 删除角色
     * @param classId
     * @return
     */
    @RequestMapping(value = "/deleteClass")
    public Result deleteClass(Integer classId){
        classService.deleteClass(classId);
        Result result = new Result();
        return result;
    }

    /**
     * 更新角色
     * @param cls
     * @return
     */
    @RequestMapping(value = "/updateClass")
    public Result updateClass(@RequestBody Cls cls){
        classService.updateClass(cls);
        Result result = new Result();
        return result;
    }

    @RequestMapping(value = "/getClassPage")
    public Result getClassPage(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = classService.getClassPage(pageNo,pageSize);
        Result result = new Result();
        result.setData(page);
        return result;

    }

    @RequestMapping(value = "/getClassList")
    public Result getClassList(){
        List<Cls> classList = classService.getClassList();
        Result result = new Result();
        result.setData(classList);
        return result;
    }

    @RequestMapping(value = "/getClassByClassId")
    public Result getClassByClassId(Integer classId){
        List<Cls> classByClassId = classService.getClassByClassId(classId);
        Result result = new Result();
        result.setData(classByClassId);
        return result;

    }
}
